package DramCore
{
	import mx.containers.Canvas;
	import flash.display.*;
	import flash.net.URLRequest;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import utils.Trace;
	import mx.core.UIComponent;
	import flash.events.MouseEvent;
	import mx.core.Application;
	
	public class PlaceLayer extends Canvas
	{
		private var _pictLdr:Loader = new Loader();
		public var _hotspotScript:String;
		public var hotspotSoundFX:String;
		
		public function PlaceLayer( name:String )
		{
			super();
			var pictURL:String = name;
			var pictURLReq:URLRequest = new URLRequest(pictURL);
			this._pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded); 
			this._pictLdr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, reportIOError,false,0,true);
 			this._pictLdr.load(pictURLReq);
		}
		private function imgLoaded(e:Event):void
		{
        	var uic:UIComponent = new UIComponent();
    		this.addChild( uic );
      		uic.addChild ( this._pictLdr.content);
  		    this._pictLdr = null;
 		}
		private function reportIOError( event:Event ):void {
			Trace.throwError("ScriptCompiler.loadScript IOError: "+event.toString() );
		}
		public function set hotspotScript( script:String ):void {
			this._hotspotScript = script;
			if( script != ""){
				this.addEventListener(MouseEvent.MOUSE_DOWN, handleHotSpotCallScript ,false,0,true);
			} else {
				this.removeEventListener(MouseEvent.MOUSE_DOWN, handleHotSpotCallScript );
			}
		}
		
		private function handleHotSpotCallScript( e:Event ):void {
			Trace.myTrace("handleHotSpotCallScript");
			Application.application._game.executeCommand( "game", "callscript", new Array( this._hotspotScript ) );
		}
	}
}